#pragma once

#include <string>
#include <map>
#include <unordered_map>
#include "base/Define.h"
#include "protocol/routeinfo.pb.h"
#include "protocol/transport.pb.h"
#include <memory>
#include <shared_mutex>
#include "consumer/client/MessageSubscriber.h"
#include "consumer/client/RouteInfoDownloader.h"

namespace zeroplus::mq::consumer
{
    enum EventType : uint8_t
    {
        Connect,
        Subscribe
    };

    class ConsumerMediator
    {
    private:
        std::shared_ptr<RouteInfoDownloader> routeInfoDownloader_;
        std::shared_ptr<MessageSubscriber> messageSubscriber_;

    public:
        ConsumerMediator() {}

        void Notify(const EventType &sender, const Bytes &data)
        {
            switch (sender)
            {
            case Subscribe:
            {
                messageSubscriber_->SubscribeMessage(data.to_string());
                break;
            }
            case Connect:
            {
                messageSubscriber_->ConnectToBroker(data.to_string());
                break;
            }
            default:
            {
                break;
            }
            }
        }

        void setRouteInfoDownloader(std::shared_ptr<RouteInfoDownloader> routeInfoDownloader)
        {
            routeInfoDownloader_ = routeInfoDownloader;
        }

        void setMessageSubscriber(std::shared_ptr<MessageSubscriber> messageSubscriber)
        {
            messageSubscriber_ = messageSubscriber;
        }
    };
}
